package com.lsy.weizhi2.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lsy.weizhi2.activity.CustomPage;
import com.lsy.weizhi2.myutils.SearchCall;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.utils.MyMethod;
import com.zhy.autolayout.utils.AutoUtils;

/**
 * Created by 嗨哟 on 2017/3/10.
 */
public class SearchView extends LinearLayout {
    private Context context;
    private View view;
    private TextView home_addr;
    private EditText home_search_et;
    private ImageView home_search_iv;
    private SearchCall searchCall;
    private String addr;
    public SearchView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        view=LayoutInflater.from(context).inflate(R.layout.search,this,true);
        AutoUtils.autoSize(view);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        home_addr= (TextView) view.findViewById(R.id.home_addr);
        home_search_et= (EditText) view.findViewById(R.id.home_search_et);
        home_search_iv= (ImageView) view.findViewById(R.id.home_search_iv);
        home_search_et.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                CustomPage.Tag=2;
                MyMethod.toActivity(context, CustomPage.class);
            }
        });
        home_search_iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                searchCall.Search_S(view,getHome_addr(),getHome_Search());
            }
        });
        home_addr.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                searchCall.Search_Text(view);
            }
        });
    }

    public void setSearchCall(SearchCall searchCall){
        this.searchCall=searchCall;
    }

    public void setHome_addr(String addr){
        home_addr.setText(addr);
    }

    public String getHome_addr(){
        return home_addr.getText().toString().trim();
    }

    public String getHome_Search(){
        return home_search_et.getText().toString().trim();
    }
}
